home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-09-11 | 5.1 KB | 163 lines | [TEXT/CWIE] |
- // IAIndex.h
- // Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
-
- #pragma once
- #ifndef IAIndex_h
- #define IAIndex_h
-
- #pragma import on
-
- #include "IAAnalysis.h"
- #include "IANarrow.h"
-
- //#pragma IA_BEGIN_IMPORTS
- #include <time.h>
- //#pragma IA_END_IMPORTS
-
- #pragma IA_BEGIN_EXPORTS
-
- struct IAIndexTypes {
- IAIndexTypes();
- IAIndexTypes(uint32 storageType, uint32 corpusType, uint32 analysisType, uint32 indexType);
-
- // Returns true iff two IAIndexTypes are equal.
- bool Equal(IAIndexTypes* other);
- void Store(IAOutputBlock* output) const;
- void Restore(IAInputBlock* input);
-
- uint32 storageType;
- uint32 corpusType;
- uint32 analysisType;
- uint32 indexType;
- uint32 osSetType;
- private:
- void* operator new(size_t size); // stack allocate only
- };
-
- class IAIndex : public IAObject {
- public: // constructors
- IAIndex(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r = NULL);
-
- virtual ~IAIndex(); // deletes corpus, analysis & mutex
-
- // Initializes a new emtpy index in a new empty storage.
- virtual void Initialize();
- // Opens an existing index.
- // By default, Calls Open() on the storage, corpus and analysis.
- virtual void Open();
-
- // Uses the corpus iterator to add new documents and delete expired documents.
- // Simple applications should be able to maintain an index with just this method,
- // Complex applications will need the more fine-grained control of the subsequent methods.
- virtual void Update();
-
- // Adds a document to the index.
- virtual void AddDoc(IADoc* doc) = 0;
- // Updates the indexes references to an (unchanged) document.
- virtual void RenameDoc(const IADoc* oldName, const IADoc* newName) = 0;
- // Removes a no-longer extant document (i.e., won’t call Text(id)).
- virtual void DeleteDoc(const IADoc* doc) = 0;
- // Flushes all changes. Call just before storage->Commit().
- virtual void Flush();
- // Returns the time of the last call to Flush().
- time_t UpdateTime() { return updateTime; }
- // Attempts to compact the index.
- virtual void Compact();
-
- // Merges an array of indices into an index.
- // The index, corpus and analysis classes must be the same for all indices.
- // The indices must be disjoint -- no documents may be indexed in more than one index.
- virtual void Merge(IAIndex** indices, uint32 indexCount) = 0;
-
- // Returns true if a document is indexed.
- virtual bool IsDocIndexed(const IADoc* doc) = 0;
-
- // Returns the total number of documents indexed.
- virtual uint32 GetDocCount() = 0;
-
- // Returns an iterator over all the documents indexed.
- virtual IADocIterator* GetDocIterator() = 0;
- virtual IADocIterator* GetDocIterator(const IADoc* start) = 0;
-
-
- // Accesses the types of an index. May be called at any time.
- void GetIndexTypes(IAIndexTypes* types);
-
- IADefineNarrowMethods(IAIndex, IAIndex); // support for IANarrow
-
- virtual IAAnalysis* GetQueryAnalysis() const;
- void SetPreferredAnalysis(const IAAnalysis* analysis = NULL);
- IAAnalysis* GetPreferredAnalysis() const;
-
- IAStorage* GetStorage() const {return storage;}
- IACorpus* GetCorpus() const {return corpus;}
- IAAnalysis* GetAnalysis() const {return analysis;}
- uint32 GetIndexType() const {return indexType;}
- IABlockID GetIndexRoot() const {return indexRoot;}
-
- void SetMaxDocumentSize(uint32 s = 2000) {fMaxDocSize = s;}
- uint32 GetMaxDocumentSize() const {return fMaxDocSize;}
-
- protected:
- // Root is stored by Initialize()--before Initializing() is called--and by Flush().
- // The root is restored by Open().
- // Subclasses can add data to the root block by defining these.
- virtual IABlockSize RootSize();
- virtual void StoreRoot(IAOutputBlock* output);
- virtual void RestoreRoot(IAInputBlock* input);
- // Subclasses can add subsequent initializations by defining this.
- // The base implementation initializes the corpus and analysis.
- virtual void Initializing();
-
- // Stored in the root block:
- time_t updateTime;
- IABlockID corpusRoot;
- IABlockID analysisRoot;
-
- bool isOpen;
- IAMutex* mutex;
-
- // default constructor etc. so that this can be a virtual base class
- IAIndex();
- void Constructing(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r);
- bool isConstructed;
- private:
- IAAnalysis* fPreferedAnalysis; // if set then is used for quey analysis
-
- IAIndex(IAIndex&); // don't define a copy constructor
-
- IAStorage* storage;
- IACorpus* corpus;
- IAAnalysis* analysis;
-
- uint32 indexType;
- IABlockID indexRoot;
-
- // The maximum number of tokens indexed per doc.
- // Documents longer than this are currently truncated.
- uint32 fMaxDocSize;
-
-
- };
-
- void IAReadIndexTypes(IAStorage* storage, IABlockID indexRoot, IAIndexTypes* types);
-
- IAExceptionCode IndexInvalid = 'VIIV';
- IAExceptionCode IndexNotInitialized = 'VINI';
- IAExceptionCode IndexNotOpen = 'VINO';
- IAExceptionCode IndexAlreadyOpen = 'VIAO';
- IAExceptionCode IndexDocAlreadyIndexed = 'VIAI';
- IAExceptionCode IndexDocNotIndexed = 'VIDN';
-
- inline IAAnalysis* IAIndex::GetPreferredAnalysis() const
- {
- return fPreferedAnalysis;
- }
-
-
- #pragma IA_END_EXPORTS
-
- #pragma import reset
-
- #endif
-